define(function(){
    return {
        init:function(res){
            // console.log(res)
            let i = 0;
            res.some((val,idx)=>{
                i = idx;
                return val.goodsId===id
            });
    
            // console.log(res[i])
            
            let imglist="";
            for(var j=0;j<res[i].img.length;j++){
                imglist += `<li><img src="${res[i].img[j].small}" alt=""></li>`;
            }
    
            let imgbox = `<div class="smallImg">
                    <img src="${res[i].img[0].small}" alt="">
                    <span></span>
                </div>
                <ul>
                    ${imglist}
                </ul>
                <div class="largeImg">
                    <img src="${res[i].img[0].large}" alt="">
                </div>`;
    
            let colorlist="";
            for(var j=0;j<res[i].colors.length;j++){
                colorlist += `<li>
                                <span style="background:${res[i].colors[j].color}"></span>
                                <em>${res[i].colors[j].title}</em>
                            </li>`;
            }
            let infobox = `<h2>${res[i].name}</h2>
                <p>价格：<span>${res[i].price}</span></p>
                <p>销量：<span>${res[i].sales}</span></p>
                <p>剩余：<span>${res[i].stock - res[i].sales}</span></p>
                <ul>
                    ${colorlist}
                </ul>`;
    
    
            $(".imgbox").html(imgbox);
            $(".infobox").html(infobox);
            
        },
        addFn:function(m,s,c){
            // 添加放大镜功能
            m()
            // 添加点击切换图片功能
            s()
            // 添加购物车功能
            c()
        }
    }
})